//教材章节数据集合。
Ext.define("ES.store.TeachingSectionsStore",{
    extend:"Ext.data.Store",
    model:"ES.model.TeachingSectionsModel",
    pageSize:20,
    remoteSort:true,
    autoLoad: false,
    proxy:{
        type:"ajax",
        url:"TeachingSections!list.action",
        reader:{
            type:"json",
            root:"dataSource.entityList",
            totalProperty:"dataSource.totalCounts"
        },
        listeners:{
            exception:function(proxy, resp, operation, opt){
                Ext.MessageBox.show({
                    title:"远程异常",
                    msg:operation.getError(),
                    icon:Ext.MessageBox.ERROR,
                    buttons:Ext.Msg.OK
                });
            }
        }
    },
    listeners:{
        beforeload:function(store, operation){
            Ext.getBody().mask("正在加载数据，请稍后...");
            Ext.apply(store.proxy.extraParams,{
                ascProperty:"SectionName",
                asc:false
            });
        },
        load:function(){
            Ext.getBody().unmask();
        },
        update:function(store, record){
            var currPage = store.currentPage;
            Ext.Ajax.request({
                url:"TeachingSectionsEdit!update.action",
                params:{
                    parentSectionID:record.get("parentSectionID"),
                    sectionID:record.get("sectionID"),
                    sectionName:record.get("sectionName"),
                    catalogID:record.get("catalogID"),
                    description:record.get("description")
                },
                method:"POST",
                success:function(){
                    store.removeAll();
                    store.loadPage(currPage);
                }
            });
        },
        remove:function(store, record){
             var currPage = store.currentPage;
              Ext.Ajax.request({
                   url:"TeachingSectionsEdit!delete.action",
                   params:{
                       sectionID:record.get("sectionID")
                   },
                   method:"POST",
                   success:function(){
                    store.removeAll();
                    store.loadPage(currPage);
                 }
              });
        }
    }
})